

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Equip extends JFrame{
    public Equip(String userid){

        SQLOperation sql=new SQLOperation();

        setTitle("Equip Operation");
        setLayout(null);
        Container container=getContentPane();
        setLayout(new BorderLayout());

        JPanel panel1=new JPanel();

        JLabel title=new JLabel("Equip Operation");
        title.setFont(new Font("",Font.BOLD,25));
        panel1.add(title);
        add(panel1,BorderLayout.NORTH);

        JPanel search=new JPanel();
        JLabel attri=new JLabel("Search:");
        search.add(attri);

        JTextField equipSearch=new JTextField(20);
        search.add(equipSearch);

        add(search,BorderLayout.CENTER);


        JButton back=new JButton("Back");
        back.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
                new ManagerDefaultFrame(userid);
            }
        });

        JButton list=new JButton("List All");
        list.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // LIST ALL

                new EquipList(userid);



            }
        });

        JButton enter=new JButton("Search");
        enter.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String[] attributes={"idDevice"};
                Object[][] result=sql.search("Device",attributes,"idDevice",equipSearch.getText());

                if(result.length==0){
                    //unfound

                    JOptionPane.showMessageDialog
                            (null, "Invalid Equip ID!","Wrong ID",JOptionPane.ERROR_MESSAGE);

                }
                else{

                    new EquipSearchResult(userid,equipSearch.getText());
                    //list family detail
                }
            }
        });
        JPanel buttons=new JPanel();
        buttons.add(back);
        buttons.add(list);
        buttons.add(enter);

        add(buttons,BorderLayout.SOUTH);

        setSize(350,200);
        setResizable(false);
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        setVisible(true);


    }
}
